package com.sgq.vue.entity.system;

import com.baomidou.mybatisplus.annotation.*;

import java.util.Collection;
import java.util.List;

import com.sgq.vue.entity.base.MyBaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

/**
 * <p>
 * 
 * </p>
 *
 * @author SGQ
 * @since 2023-10-30
 */
@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = false)
@TableName("sys_user")
public class User extends MyBaseEntity implements  UserDetails {


    private static final long serialVersionUID = 1L;

    /**
     * 登录名称(用户名)
     */
    private String username;

    /**
     * 登录密码
     */
    private String password;

    /**
     * 帐户是否过期(1-未过期，0-已过期)
     */
    @TableField(fill = FieldFill.INSERT)
    private Integer isAccountNonExpired;

    /**
     * 帐户是否被锁定(1-未过期，0-已过期)
     */
    @TableField(fill = FieldFill.INSERT)
    private Integer isAccountNonLocked;

    /**
     * 密码是否过期(1-未过期，0-已过期)
     */
    @TableField(fill = FieldFill.INSERT)
    private Integer isCredentialsNonExpired;

    /**
     * 帐户是否可用(1-可用，0-禁用)
     */
    @TableField(fill = FieldFill.INSERT)
    private Integer isEnabled;

    /**
     * 真实姓名
     */
    private String realName;

    /**
     * 昵称
     */
    private String nickName;

    /**
     * 所属部门ID
     */
    private Long departmentId;

    /**
     * 所属部门名称
     */
    private String departmentName;

    /**
     * 性别(0-男，1-女)
     */
    private Integer gender;

    /**
     * 电话
     */
    private String phone;

    /**
     * 邮箱
     */
    private String email;

    /**
     * 用户头像
     */
    private String avatar;

    /**
     * 是否是管理员(1-管理员)
     */
    private Integer isAdmin;


    /**
     * 菜单列表
     */
    @TableField(exist = false)
    private List<Permission> permissions;

    /**
     * 权限列表
     */

    @TableField(exist = false)
    Collection<? extends GrantedAuthority> authorities;

    @Override
    public boolean isAccountNonExpired() {
        System.out.println("《判断账户是否过期》");
        return this.getIsAccountNonExpired() == 1 ? true : false;
    }

    @Override
    public boolean isAccountNonLocked() {
        System.out.println("《判断账户是否锁定》");
        return this.getIsAccountNonLocked() == 1 ? true : false;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        System.out.println("《判断密码是否锁定》");
        return this.getIsCredentialsNonExpired() == 1 ? true : false;
    }

    @Override
    public boolean isEnabled() {
        System.out.println("《判断密码是否可用》");
        return this.getIsEnabled() == 1 ? true : false;
    }

}
